import React, {useEffect} from 'react';
import identity from './identity';
import myIdentity from './interface';
import GenericNumber from './classes';
import loggingIdentity from './extendGenericity'

type IFoo = <T> (arg: T) => T

interface IA<T = string> {
    name: T
}

interface ITodo {
    title: string;
    description: string;
}

interface IPageInfo {
    title: string;
}

type Page = "home" | "about" | "contact"

interface IPickEg {
    completed: boolean;
    description: string;
    title: string;
}

type PickPrev = Pick<IPickEg, "completed" | "title">

const Genericity = () => {

    console.log(myIdentity('还是'))

    const foo:IFoo = <T,> (arg: T) : T => {
        return arg
    }

    const testIdentity = () => {
        const output = identity<string>('myString')
        const output2 = identity('world')
        console.log(output, output2)
    }

    const testGenericNumber = () => {
        const myGenericNumber = new GenericNumber<number>();
        myGenericNumber.zeroValue = 12;
        myGenericNumber.add = (x, y) => (x + y)

        console.log(myGenericNumber)

        const stringNumberic = new GenericNumber<string>();
        stringNumberic.zeroValue = 'hallp';
        stringNumberic.add = (x, y) => (x + y)

        console.log(stringNumberic)
        console.log(stringNumberic.add(stringNumberic.zeroValue, 'ggggo'))
    }

    const extendGener = () => {
        const str = loggingIdentity<string>('happy')
        // loggingIdentity(2)
        console.log(str.length)
    }

    const defaultType = () => {
        const myA: IA = {
            name: 'world'
        }
        const numA: IA<number> = {
            name: 233
        }
        console.log(myA, numA)
    }

    const testPratial = () => {
        const a: Partial<ITodo> = {
            title: "1"
        }
        console.log(a)
    }

    const testRecord = () => {
        const x: Record<Page, IPageInfo> = {
            about: { title: "about" },
            contact: { title: 'contact' },
            home: { title: 'home' }
        }
        console.log(x)
    }

    const testPick = () => {
        const todo: PickPrev = {
            completed: true,
            title: 'info',
        }

        console.log(todo)
    }

    useEffect(() => {
        console.log(foo('happy'))
        testIdentity()
        testGenericNumber()
        extendGener()
        defaultType()
        testPratial()
        testRecord()
        testPick()
    }, [])

    return <div>genericity</div>
}

export default Genericity;